let tileset
export function loadTile(viewer,options){
    tileset = new Cesium.Cesium3DTileset(options)
    viewer.scene.primitives.add(tileset);
    viewer.viewer.zoom(tileset);

    tileTree.root = {
        name:options.name||'rootTile',
        tileset,
        children:[]
    }
    listenerTileLoad()
    return tileset
}

let tileTree = {}
let tilesColumn = []
let tileMap = {}
function listenerTileLoad(){
    tileset.tileLoad.addEventListener(function(tile) {
        tilesColumn.push(tile)
    });
}

let name 
function setMap(tile){
    name = tile._contentHeader.uri
    tileMap[name] = tile
}

function loop(tile){
    setMap(tile)
    if(tile.children&&tile.children.length > 0 ){
        let i =0;len=tile.children.length
        for(i;i<len;i++){
            loop(tile.children[i])
        }
    }
}

/// 当前id 为 请求头文件地址
export function getTileMap(id){
    return id ? tileMap[id] : tileMap
}

/// 获取tile资源树
export function getTileSourceTree(){
    return tileTree
}